/**
 * 
 */
package com.oppo.dao;

import java.util.List;

import org.apache.commons.dbutils.handlers.BeanListHandler;

import com.oppo.bean.CarBean;
import com.oppo.bean.ProductBean;
import com.oppo.db.BasicDataOperation;
import com.oppo.tools.MyTools;

/**
 * @author 天下有雪
 *
 */
public class AddCarItemDao {
	
	/**
	 * @功能描述:执行加入购物车
	 */
	public int AddCarInfo(CarBean cb) {
		String sql = "INSERT INTO car_t(product_id,user_id,product_count,product_allprice) VALUES(?,?,?,?)";
		int i = MyTools.getNewInstance(BasicDataOperation.class).updateData(sql,cb.getProduct_id(),cb.getUser_id(),cb.getProduct_count(),cb.getProduct_allprice());
		return i;
	}
	/**
	 * @功能描述:查询要加入购物车商品的信息
	 */
	public List<ProductBean> getInfo(ProductBean pb){
		String sql = "SELECT * FROM product_t WHERE product_color = ? AND product_model = ?";
		List<ProductBean> list = MyTools.getNewInstance(BasicDataOperation.class).queryData(sql, new BeanListHandler<>(ProductBean.class), pb.getProduct_color(),pb.getProduct_model());
		return list;
	}
	/**
	 * @功能描述:查询用户的购物车内是否已经有该型号颜色的记录
	 */
	public List<CarBean> doGetCarInfo(CarBean cb){
		String sql = "SELECT * FROM car_t WHERE product_id = ? AND user_id = ?";
		List<CarBean>  list = MyTools.getNewInstance(BasicDataOperation.class).queryData(sql, new BeanListHandler<>(CarBean.class), cb.getProduct_id(),cb.getUser_id());
		return list;
	}
	/**
	 * @功能描述:在有记录情况下更新数量即可
	 */
	public int doUpdateCount(CarBean cb) {
		String sql = "UPDATE car_t SET product_count = ?,product_allprice = ? WHERE car_id = ?";
		int i = MyTools.getNewInstance(BasicDataOperation.class).updateData(sql, cb.getProduct_count(),cb.getProduct_allprice(),cb.getCar_id());
		return i;
	}
}
